'''
Created on Apr 4, 2012
TestCase ID: Ecom_5001
Description : Kiem thu chuc nang tao mot bai hoc moi
@author: Vu Dao
'''
import unittest
import time
import HTMLTestRunner
from Functions.globalFunc import preCondition, endCondition, readData
from Functions.loginPageFunc import login
from Functions.administratorFunc import clickOnBtnLessons
from Functions.lessonsFunc import clickOnCreateLesson, createLesson,\
    verifyLessonCreatedSuccessfully

username = readData("username")
password = readData("password")
nameLesson = readData("lessonName")
language = readData("language")
categoriesName = readData("categoriesLesson")
price = readData("priceLesson")
class Ecom_5001(unittest.TestCase):


    def setUp(self):
        print "Buoc 1: Mo website"
        preCondition(self)

    def test_Ecom_5001(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 3: Click vao lessons button"
        clickOnBtnLessons(self)
        
        print "Buoc 4: Click vao New lesson"
        clickOnCreateLesson(self)
        
        print "Buoc 5: Nhap day du thong tin vao cac truong bac buoc"
        createLesson(self, nameLesson = nameLesson, language = language, categories = categoriesName, price = price)
        
        print "Buoc 6: Kiem tra bai hoc duoc tao thanh cong"
        self.assertTrue(verifyLessonCreatedSuccessfully(self,nameLesson), "Failed: Bai hoc moi tao khong thanh cong")
        print "Passed: Bai hoc moi duoc tao thanh cong"
        
    def tearDown(self):
        print "Buoc 7: Dong website"
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5001)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao mot bai hoc moi'
                    )
    runner.run(suite)